package com.qingcheng.controller.comment;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.comment.Comment;
import com.qingcheng.service.comment.CommentService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/comment")
public class CommentControllerht {

    @Reference
    private CommentService commentService;

    @GetMapping("/findAll")
    public List<Comment> findAll(){
        return commentService.findAll();
    }

    @GetMapping("/findPage")
    public PageResult<Comment> findPage(int page, int size){
        return commentService.findPage(page, size);
    }

    @PostMapping("/findList")
    public List<Comment> findList(@RequestBody Map<String,Object> searchMap){
        return commentService.findList(searchMap);
    }

    @PostMapping("/findPage")
    public PageResult<Comment> findPage(@RequestBody Map<String,Object> searchMap,int page, int size){
        return  commentService.findPage(searchMap,page,size);
    }

    @GetMapping("/findById")
    public Comment findById(byte[] id){
        return commentService.findById(id);
    }


    @PostMapping("/add")
    public Result add(@RequestBody Comment comment){
        commentService.add(comment);
        return new Result();
    }

    @GetMapping("/delete")
    public Result delete(byte[] id){
        commentService.delete(id);
        return new Result();
    }

    /**
     * 根据用户名查找评论列表
     * @return
     */
    @GetMapping("/listByUsername")
    public List<Comment> listByUsername(String username){

        return  commentService.findByUsername(username);
    }

    /**
     * 修改评论的状态
     * @param comment
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Comment comment){
        commentService.update(comment);
        return new Result();
    }

    /**
     * 过滤敏感词
     * @param comment
     * @return
     */
    @PostMapping("/sensitiveWordmask")
    public String sensitiveWordmask(@RequestBody Comment comment){
        String wordmask = commentService.sensitiveWordmask(comment);
        return wordmask;
    }
}
